/*-
 * Copyright (c) 2006, 2007 FTS Team
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the FTS Team nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *      StopWords.hpp
 *
 * $FTS$
 */
#ifndef _STOP_WORDS_HPP__
#define _STOP_WORDS_HPP__ 1

/**
  @file StopWords.hpp
  @brief Stop words for FTSS indexer and retriever
*/

#include <DataDumper.hpp>
#include <Hash.hpp>
#include <HashFunctions.hpp>

#define C_STOP_WORDS_READABLE "Stop Words Index"
#define C_STOP_WORDS_TYPE     0x00000001

namespace FTSS // FullTextSearchSystem
{
// FWD
class LemmatizerInterface;

/**
  @class StopWords StopWords.hpp <StopWords.hpp>
  @brief List of stop words
*/
class StopWords
{
public:
	/**
	  @brief Constructor
	  @param oILemmatizer - lemmatizer interface
	*/
	StopWords(LemmatizerInterface & oILemmatizer);

	/**
	  @brief Add word to stopword list
	  @param szWord - Word
	  @param iWordLength - Word length
	  @param iLemmatize - if set to 1, use lemmatizer
	*/
	void AddWord(CCHAR_P szWord, const UINT_32 & iWordLength, const INT_32 & iLemmatize = 0);

	/**
	  @brief Remove word from stoprword list
	  @param szWord - Word
	  @param iWordLength - Word length
	  @param iLemmatize - if set to 1, use lemmatizer
	*/
	void RemoveWord(CCHAR_P szWord, const UINT_32 & iWordLength, const INT_32 & iLemmatize = 0);

	/**
	  @brief Check word in stop word list
	  @param szWord - Word
	  @param iWordLength - Word length
	  @param iLemmatize - if set to 1, use lemmatizer
	  @return 0 if found, -1 - if not
	*/
	INT_32 CheckWord(CCHAR_P szWord, const UINT_32 & iWordLength, const INT_32 & iLemmatize = 0);

	/**
	  @brief Check word in stop word list
	  @param iWordHash - Hash of word
	  @return 0 if found, -1 - if not
	*/
	INT_32 CheckWord(const TokenHash_t & iWordHash);

	/**
	  @brief Serialize and dump object
	  @return 0 success, -1 - if any error occured
	*/
	INT_32 Dump(DataDumper * pObject);

	/**
	  @brief Restore and de-serialize object
	  @return 0 success, -1 - if any error occured
	*/
	INT_32 Restore(DataDumper * pObject);

	/**
	  @brief A Destructor
	*/
	~StopWords() throw();

private:
	/**
	  @typedef Pair<TokenHash_t, CHAR_8> StopWordPair
	  @brief Data storage key => value pair type definition
	*/
	typedef Pair<TokenHash_t, CHAR_8> StopWordPair;

	/**
	  @typedef Hash<TokenHash_t, CHAR_8, HashHasher, HashComparator> StopWordHash
	  @brief Data storage type definition
	*/
	typedef Hash<TokenHash_t, CHAR_8, HashHasher, HashComparator> StopWordHash;

	/** Lemmatizer instance      */
	LemmatizerInterface  & oLemmatizer;
	/** Data storage             */
	StopWordHash           oStopWordHash;
};

} // namespace FTSS
#endif // _STOP_WORDS_HPP__
// End.
